import 'dart:ffi';
import 'dart:async';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:fun4live/pages/appSytyle.dart';
import 'package:get/get.dart';
import 'live_room_controller.dart';
import 'package:floating/floating.dart';
import 'package:fijkplayer/fijkplayer.dart';
class LiveRoomPage extends GetView<LiveRoomController>{
  const LiveRoomPage({Key?key}):super(key: key);

  @override
  Widget build(BuildContext context)
  {
    return buildPageUI();
    final page = Obx(
      (){
          return buildPageUI();
        }
      );
      return Scaffold(
      body: buildMediaPlayer(),
      );
  }

  Widget buildPageUI(){
    return OrientationBuilder(
      builder: (context,orientation){
        return Scaffold(
          appBar: AppBar(
            title:Obx(
              () =>Text(controller.detail.value?.title??"直播间") ,
              ),
            actions: buildAppbarActions(context),
          ),
          //body: orientation == Orientation.portrait
         // ? buildPhoneUI(context)
         // :buildTableUI(context),
         body: buildPhoneUI(context),
          );
      });
  }

  Widget buildPhoneUI(BuildContext context){
    return Column(
      children: [
        AspectRatio(
          aspectRatio: 16 / 9,
          child: buildMediaPlayer(),
          ),
        //buildUserProfile(context),
        //buildMessageArea(),
        //buildBottomActions(context),

      ],
      );
  }

  Widget buildTableUI(BuildContext context){
    return Column(
      children: [
        Expanded(
          child: Row(
            children: [
              Expanded(child: buildMediaPlayer(),),
              SizedBox(
                width: 300,
                child: Column(
                  children: [
                    //buildUserProfile(context),
                    //buildMessageArea(),
                  ]),
              ),
            ],)
            ),
            Container(
              decoration: BoxDecoration(
                color: Theme.of(context).cardColor,
                border: Border(
                  top: BorderSide(color: Colors.grey.withOpacity(.1)
                  )
                )
              ),
              padding: AppStyle.edgeInsetsV4.copyWith(
                bottom: AppStyle.bottomBarHeight + 4
              ),
            )
      ],);
  }

  Widget buildMediaPlayer(){
    var boxFit = BoxFit.contain;
    double? AspectRatio = 16 / 9;
    return Stack(
      children: [
        FijkView(
        player: controller.player
      ),
        Obx(
          () => Visibility(
            visible: !controller.liveStatus.value,
            child: const Center(
              child: Text(
                "未开播",
                style: TextStyle(fontSize: 16, color: Colors.white),
              ),
            ),
          ),
        ),
      ]
    );    
}
  List<Widget> buildAppbarActions(BuildContext context) {
    return [
      IconButton(
        onPressed: () {
         // showMore();
        },
        icon: const Icon(Icons.more_horiz),
      ),
    ];
  }

}